package cn.zyjw.service.impl;

import cn.zyjw.domain.Notice;
import cn.zyjw.mapper.NoticeMapper;
import cn.zyjw.service.NoticeService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

@Service
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> implements NoticeService {

    /**
     * 列表分页查询
     *
     * @param page
     * @param title
     * @param startTime
     * @param endTime
     * @param status
     * @return
     */
    @Override
    public Page<Notice> listByPage(Page<Notice> page, String title, String startTime, String endTime, Integer status) {
        LambdaQueryWrapper<Notice> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StringUtils.isNotBlank(title), Notice::getTitle, title)
                .between(
                        StringUtils.isNotBlank(startTime) && StringUtils.isNotBlank(endTime),
                        Notice::getCreated,
                        startTime,
                        endTime + " 23:59:59")
                .eq(status != null, Notice::getStatus, status);
        page.addOrder(OrderItem.desc("last_update_time"));
        return this.page(page, queryWrapper);
    }
}
